package com.study.business.controller.admin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.study.server.domain.Section;
import com.study.server.dto.SectionDto;
import com.study.server.dto.PageDto;
import com.study.server.dto.ResponseDto;
import com.study.server.exception.ValidatorException;
import com.study.server.service.SectionService;
import com.study.server.util.ValidatorUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/admin/section")
public class SectionController {

    @Resource
    private SectionService service;

    private static final Logger LOG = LoggerFactory.getLogger(ChapterController.class);
    public static final String BUSINESS_NAME = "小节";
    /**
     * 查询
     * @param pageDto
     * @return
     */

   @RequestMapping(value = "/list")
   public ResponseDto get(@RequestBody PageDto pageDto){
        ResponseDto objectResponseDto = new ResponseDto();
         System.out.println("pageDto {}"+pageDto);
        service.list(pageDto);
       objectResponseDto.setContent(pageDto);
     return objectResponseDto;
   }

    /**
     * 保存
     * @param sectionDto
     * @return
     */
   @RequestMapping(value = "/save")
   public ResponseDto save(@RequestBody SectionDto sectionDto){

     //       ValidatorUtil.require(sectionDto.getName(),"，课程");
      //      ValidatorUtil.require(sectionDto.getCourseId(),"，课程ID");
       //     ValidatorUtil.length(sectionDto.getCourseId(),"，课程ID",1,8);
        ValidatorUtil.require(sectionDto.getTitle(), "标题");
        ValidatorUtil.length(sectionDto.getTitle(), "标题", 1, 50);
        ValidatorUtil.length(sectionDto.getVideo(), "视频", 1, 200);

       ResponseDto objectResponseDto = new ResponseDto();
       System.out.println("sectionDto {}"+sectionDto);
      service.save(sectionDto);
       objectResponseDto.setContent(sectionDto);
     return objectResponseDto;

   }


    /**
     * 删除
     * @param
     * @return
     */
   @DeleteMapping(value = "/del/{id}")
   public ResponseDto del(@PathVariable String id){
       ResponseDto objectResponseDto = new ResponseDto();
       System.out.println("id {}"+id);
      service.del(id);

     return objectResponseDto;

   }
}
